<style lang="scss">
  @import 'index';
</style>

<template>
  <div class="ga-container">
    <div class="ga-recharge">
      <div class="box">
        <label class="label">充值金额</label>
        <div class="ga-input-group">
          <span class="money">¥</span>
          <div class="input-group">
            <input class="input" type="number" placeholder="请输入充值金额" v-model="amount">
          </div>
        </div>
      </div>

      <div class="btn-box">
        <!--disable 禁止点击-->
        <button class="btn blue mt20" @click="recharge">下一步</button>
      </div>
    </div>
  </div>
</template>

<script>
import {isLogin} from '@/utils/handleLogin'
export default {

  data () {
    return {
        amount: ''
    }
  },
  methods: {
     async recharge () {
      if(!this.amount){
        return false
      }
      let params = {
         amount: this.amount
      }
      let that = this
      this.$_util.ajax.post('https://guo-a.com/mapi/pay/rechange?token=' + this.$store.state.Token,params).then((res)=>{
         console.log(res)
         if(res.code === 200){
            wx.requestPayment({
              'timeStamp': res.data.timeStamp,
              'nonceStr': res.data.nonceStr,
              'package': res.data.package,
              'signType': res.data.signType,
              'paySign': res.data.paySign,
              'success': function(dd){
                if(dd.errMsg == "requestPayment:ok"){
                  // 调用支付成功
                         wx.navigateBack()
                }else if(dd.errMsg == 'requestPayment:cancel'){
                  // 用户取消支付
                }
                      
              },
              'fail': function(dd){
                wx.navigateBack()
                return false
              },
              'complete': function(dd){

              }
            })
         }
      })
     },
     /**
         * 路由跳转
         */
        bindNavigateTo (url) {
            wx.navigateTo({
              url
            })
        },
  },
  onShow () {
     isLogin()
  }
}
</script>
